﻿/**
 *
 *
 *my1
 *
 *
 *
 */
 
 
/* 
  if (!cmy1)  var cmy1:my1 = new my1();
 
class my1 {
	
	function my1() {}
	
	public function ff() {
		trace("my111111111111111");
	}

}

ok.addEventListener(MouseEvent.CLICK, function(){
												
});

*/



function strstr(sd, sc) {
	var index = sd.toString().indexOf(sc);
	return index > -1 ? sd.substring( index ) : null;  
}


function stristr(sd, sc) {
	var index = sd.toString().toLowerCase().indexOf(sc.toLowerCase());
	return index > -1 ? sd.substring( index ) : null;  
}


function allob(ob) {
	for (var i in ob)
			trace(i + " : " + ob[i]);	
}


function isE(ob, class_){
	return class_.prototype.isPrototypeOf(ob); 
	//trace (a);
}

function a(s){
		trace (s);
}

function dump(ob, bord="") {
			for (var i in ob)
					if (typeof ob[i] == 'object') {
					 	trace (bord + i + "->");
					  	dump(ob[i], bord+i.toString().replace(/[\S\s]/g,' ')+' ');
					} 
					   else trace( bord + i + ' : ' + ob[i], typeof ob[i]);	
		}



function isA(ob) {
    return Array.prototype.isPrototypeOf(ob);
  }


function isF(ob) {
	// alter -  obj is Function
    return Function.prototype.isPrototypeOf(ob);
    
   }

function isO(ob) {
  	  //return Object.prototype.isPrototypeOf(ob); // no work!
  	  	return typeof ob == 'object'; 
   }


function cpyob (d,s, noreplace = false) {
	   for (var p in s) {
			   if (isO(s[p]) && !isF(s[p])) {
				   if ((!(p in d) && noreplace) || !noreplace)	{ 
					   			d[p] = isA(s[p]) ? [] : {};
					   			cpyob(d[p],s[p], noreplace);
					   		}
			   } else {
				   		if ((!(p in d) && noreplace) || !noreplace) {
				   			d[p] = s[p];
				   		}
				   }
	   }
   }

//оболочка 
function gcpyob(s, noreplace = false){
	var d = {};
	cpyob(d, s, noreplace);
  return d;	
}



function cloneob(ob){
	var res = {};
	cpyob(res, ob);
	return res;
}

function getser(ob, infun = false):String {
	  var s:String;
	  isA(ob) ? s = "[" : s = "{";
	  for (var p in ob)
		  if (!isF(ob[p]) || infun) {
			if (typeof ob[p] == "object") {
					s+= (s.charAt(0)=='{' ? p+":" : "") + getser(ob[p]) + '|';
			}
					else	{
						s+=(s.charAt(0)=='{' ? p+":" : "") + ob[p]  +'|' ;
					}
		  }
	  s = (s.length > 1?s.substring(0,s.length-1):s) + (isA(ob) ? s = "]" : s = "}");
	  return (s);
}




function getuser(s:String):Object {
 	
   function getpar(par)	{
		   var ops = 0;
		   var opq = 0;
		   var res = [];
		   var g = "";
		   for (var i = 0; i<par.length; i++) {
			    if (par.charAt(i) == "{") 	ops++;
			    if (par.charAt(i) == "[")   opq++;
			    if (par.charAt(i) == "}") 	ops--;
			    if (par.charAt(i) == "]")  opq--;
			    if (par.charAt(i)=="|" && ops==0 && opq==0) {
			    	res.push(g);
			    	g="";
			    	continue;
			    }
			    g+=par.charAt(i);
		   }
		   if (g!="") res.push(g);
		   return (res);		   
	   }
	   
	 	
	  var ob;
	  s.charAt(0)=="[" ? ob = [] : ob = {};
	  //a("1",s);
	  var m = getpar(s.substring(1,s.length - 1));
	  for (var i = 0; i<m.length; i++) {
		  if (m[i].charAt(0)=="[" || m[i].charAt(0)=="{") {
			  ob[i] = getuser(m[i]);
		  }
		  else {
			  var m2 = m[i].match(/([\.\s\&\$\#\-\`\w\/]+)\:?([\s\S]+)?/).slice(1);
			  if (m2[1] && (m2[1].charAt(0) == '[' || m2[1].charAt(0) == '{')) {
				  ob[m2[0]] = getuser(m2[1]);
				  //if (m2[0]=='forseK1K2') a();
			   }  else {
			   			if (s.charAt(0) == "[") {
		   						m2[1] = m2[0];
		   						m2[0] = i;
		   					 }
		   			//if (m2[1] && m2[1].indexOf("function") > -1) 
		   				//eval("ob[m2[0]] = " + (m2[1]));
 		   			 		//else  
 		   			 			//if(m2[1] != undefined) ob[m2[0]] =  m2[1].toString().match(/^[\d\.\-]+$/) || m2[1]=='0'  ?  parseFloat(m2[1]) : m2[1];
								//if(m2[1] != undefined) ob[m2[0]] =  parseFloat(m2[1].toString()) || m2[1]=='0'  ?  parseFloat(m2[1]) : m2[1];
								if(m2[1] != undefined) ob[m2[0]] =  m2[1].toString().match(/^[\-\d\.]+$/)  ?  parseFloat(m2[1]) : m2[1];
		   				
		   			}
		  }
	  }
	  return (ob);
  }



/*
function getserlua(ob, infun = false, recurse = true, except="", offsindex=0):String {
	  var s:String;
	  s = "{";
	  if (isA(ob)) var isa = true;       
	  for (var p in ob)
		  if ((!isF(ob[p]) || infun) && !stristr(except, p.toString())) {
			if (typeof ob[p] == "object") {
				if (!recurse) continue;
					s+=  ( p is Number ? '['+(p+offsindex)+']=' : p+'=' ) + getserlua(ob[p], infun, recurse, except, offsindex);
				}
					else { 
						s+= (p is Number ? '['+(p+offsindex)+']=' : p+"=")+ (typeof ob[p] == "string" ?  '"'+ob[p]+'"'  : ob[p]) +';' ;
					}
		  }
	  return (s+"};");
}
*/

function getserlua(ob, infun = false, recurse = true, except="", offsindex=0):String {
	  var s:String;
	  s = "{";
	  if (isA(ob)) var isa = true;       
	  for (var p in ob)
		  if ((!isF(ob[p]) || infun) && !stristr(except, p.toString())) {
			var hh = p.toString().charAt(0)=='"';  
			if (typeof ob[p] == "object") {
				if (!recurse) continue;
				//if (p.charAt(0)=='"') p = parseInt(p.substr(1));
					s+=  ( p is Number || hh ? '['+(p+(hh?"":offsindex))+']=' : p+'=' ) + getserlua(ob[p], infun, recurse, except, offsindex);
				}
					else { 
						s+= (p is Number || hh ? '['+(p+(hh?"":offsindex))+']=' : p+"=")+ (typeof ob[p] == "string" ?  '"'+ob[p]+'"'  : ob[p]) +';' ;
					}
		  }
	  return (s+"};");
}



function getuserlua(s:String):Object {

	function getpar(par)	{
		   var ops = 0;
		   var opq = 0;
		   var res = [];
		   var g = "";
		   for (var i = 0; i<par.length; i++) {
			    if (par.charAt(i) == "{") 	ops++;
			    if (par.charAt(i) == "[")   opq++;
			    if (par.charAt(i) == "}") 	ops--;
			    if (par.charAt(i) == "]")  opq--;
			    if (par.charAt(i)==";" && ops==0 && opq==0) {
			    	res.push(g);
			    	g="";
			    	continue;
			    }
			    g+=par.charAt(i);
		   }

		   if (g.length>1 && !g.match(/^\s+$/)) res.push(g);
		   return (res);		   
	   }
	   
	 	
	  var ob;
	  //s.charAt(0)=="[" ? ob = [] : ob = {};
	  s = s.replace(/[\r\s\n]+$/,"");
	  //ob = s.match(/^\{[\r\n\s\t]*\[/) ?  [] : {};
	  var isA  = s.match(/^\{[\r\n\s\t]*\[/);
	  ob = {};
		//trace(s, s.match(/^\{[\r\n\s\t]*\[/));								  
	  var m = s.charAt(0)=="{" ? getpar(s.substring(1,s.length - 2)) : getpar(s);
	  //var m = s;
	 // trace("m = ",m);
	  for (var i = 0; i<m.length; i++) {
		  if (m[i].charAt(0)=="{") {
			  ob[i] = getuserlua(m[i]);
		  }
		  else {
			  if (m[i].toString().indexOf('=')>-1)
				  var m2 = m[i].match(/([\[\]\.\&\$\#\-\`\w\/\'\"]+)\s*\=\s*([\s\S]+)?/).slice(1);  							    //"'
						else m2 = [m[i], undefined];  
			  //m2[1]=m2[1].replace(/[\r\s\n]+$/,"");			
			  //trace("m2 = ",m2, ob is Array);
		      if (m2[1] && (m2[1].charAt(0) == '[' || m2[1].charAt(0) == '{')) {
				  //if (m2[0]=='forseK1K2') a();
				 //m2[0].charAt(0) == '[' ?  ob[ parseInt(m2[0].match(/\d+/))-1] =  getuserlua(m2[1]) :  ob[m2[0]] =  getuserlua(m2[1]); 
				 //trace(m2, m2[0].match(/\w+/));
				 m2[0].charAt(0) == '[' ?  ob[m2[0].match(/\w+/)]  =  getuserlua(m2[1]) :  ob[m2[0]] =  getuserlua(m2[1]);
				 // ob[m2[0]] = getuserlua(m2[1]);
			   }  else {
			   			//if (ob is Array) {
			   			if (isA) {
								//trace("mm2",m2,i);
		   						//m2[0] = m2[0].match(/\w+/);
		   						m2[0] = m2[0].match(/[\w\'\"]+/);                                                       //"'
		   						//m2[0] = parseInt(m2[0].match(/\d+/))-1;
			   					// a(m2[0]);
			   					//a("Ssssssssssss");
		   					 }
								if(m2[1] != undefined) ob[m2[0]] =  m2[1].toString().match(/^[\-\d\.]+$/)  ?  parseFloat(m2[1]) :  m2[1].charAt(0)=="'" || m2[1].charAt(0)=='"' ? m2[1].substring(1,m2[1].length-1) : m2[1].match(/^(false|true)$/) ? m2[1] == "true" : m2[1]; 
		   							else ob[m2[0]] = undefined;
		   			}
		  }
	  }
	  return (ob);
  }



function resetindex(ob, beginindex=1){
					var n = beginindex;			 
					var ob2 = {};
					for (var i in ob) ob2[i is Number ? n++ : i] = ob[i];
					for (var i in ob) delete ob[i];
					for (var i in ob2) ob[i] = ob2[i];
}	

		


function delp(ob, el/*or n array*/, ri=1){
	if (ob.splice) ob.splice(el, 1);	
		else delete ob[el];
		if (typeof ri == 'number') resetindex(ob, ri);
}

function addp(ob, value, offsetindex=1 ){
	//dump(gettranc(ob));
	if (ob.push) ob.push(value);	
		else 
			ob[getFirstUniq(gettranc(ob), null, offsetindex)] = value;
}


function appendp(ob, value, offsetindex=1){
	if (ob.push) ob.push(value);	
		else { 
			var k = 0;
			for (var i in ob) if (i is Number && i>k) k = i;
			 ob[k + offsetindex] = value; 
		}
	return 	k + offsetindex;
}


/*
 * gg.ff = 1; gg.aa="ss"; .....   
 * 
 */
function getLuaSave(ob, pref){
	var s ="";
	for (var i in ob)
		if (typeof ob[i] == "object") 
			s+= getLuaSave(ob[i], pref+ (ob is Array ? '['+(i+1)+']' : '.'+i));
		else	
			s+= pref + (ob is Array ? '['+(i+1)+']=' : '.'+i+"=") + (typeof ob[i] == "string" ?  '"'+ob[i]+'"'  : ob[i]) +';' ;
 return s;			
}







/**
*@version 2
*/
function basename(s, sl:String = "/\\"){
	var n = s.length;
  	while (n--) 
  		if (sl.indexOf(s.charAt(n)) > -1)   { s = s.substring(++n, s.length);  break;}
  		
  return s;		
}

function dirname(dir) {
		return dir ? dir.match(/(.+)[\\\/][\-\w\.\!]*$/)[1] : "____________________";
}

//dir 0
function hostname(dir) {
			return dir ? dir.match(/(http\:\/\/)?([\w\-\.]+)/)[2] : "____________________";
}



function haschi(ob){
		return "numChildren" in ob && ob.numChildren;
}


/**
 * var mm = hasparent(comb1.getChildByName('instance22'),"s");
  if (mm.length) ... 
 * 
 */
  
function hasparent(ob, ename = "*"){
	var m = [];
	var msub = ename.split(",");
	while((ob = ob.parent)) {
		   for (var n=0; n<msub.length; n++)
   		   if (stristr(ob.toString(), msub[n]) || ename == "*") m.push(ob);
	}
	return  m;
}



/**
 * 
 * 		var setEnabled = function(ch){
					getchi(place, "*", false, null, function(el){
						if ("enabled" in el){
							el.enabled = ch;
							//el.alpha = el.enabled ? 1 : 0.3; 
						}
					});
				};
 * 
 * 
 */
function getchi(ob, ename = "*", recurse=false, m:Array=null, fcall = null) {
	if (!m) m = [];
	var i = haschi(ob);
	var msub = ename.split(",");
	while(i--) {
		var chi = ob.getChildAt(i);
		for (var n=0; n<msub.length; n++){
			//if (recurse && haschi(chi)) m = getchi(chi, msub[n], true, m, fcall);
			if (chi is DisplayObjectContainer) m = getchi(chi, msub[n], true, m, fcall);                  //!!!!!!!!!!!!!!!!!!!!!!!!!!
			//a(chi.toString());
			if (stristr(chi.toString(), msub[n]) || ename == "*"){
				if (fcall) fcall( chi );				
				m.push(chi);
			 }
				
        }
	}
  return(m);	
}


function onloadroot(fcall, place = null){
	
	function nikola(e){
			removeEventListener(Event.EXIT_FRAME, nikola);
			fcall.call(place ? place : this);
	}

	addEventListener(Event.EXIT_FRAME, nikola);
}


function setsize(ob, size = 12){
	var tf:TextFormat = new TextFormat();
	tf.size = size;
	ob.setStyle("textFormat", tf); 
	return tf;
}



function printm  (mob, recurse=false, s="") {
	var m = getchi(mob, "*");
	for (var i=0; i<m.length; i++) {
		trace(s + i + " : " + m[i] + " : " + m[i].name +  ("text" in m[i] ? " text = "+m[i].text : "") + ("label" in m[i] ? " label = "+m[i].label : ""), "index=" + m[i].parent.getChildIndex(m[i]) );
		if (recurse && haschi(m[i])) printm(m[i], true, s + "    "); 
	}
}



function getform(ob, ename = "*", recurse = false){
	var res = {};	
	var mel = [
					'[object TextInput]',
					'[object ComboBox]',
					'[object CheckBox]',
					'[object RadioButton]',
					'[NumericStepper]'
				 ];
				 
	var m = getchi(this.parent, ename, recurse);
	for (var i=0; i<m.length; i++){
	    	//if ("text" in m[i]) res[m[i].name] = m[i].text;
	    if (!hasparent(m[i], mel.join()).length)
			switch (m[i].toString()){
					case  mel[0]  :
					case  mel[1]  : 
												 res[m[i].name] = m[i].text;//  res[m[i].name + '_ob'] = m[i];  
							   					 break;
					case  mel[2]  :
					case  mel[3]  : 
												 res[m[i].name] = m[i].selected;  
							   					 break;
			}
		
	}
	return res;
}


function setform(ob, prop, recurse = false){
	var mel = [
					'[object TextInput]',
					'[object ComboBox]',
					'[object CheckBox]',
					'[object RadioButton]'
				 ];
				 
	var m = getchi(this.parent, "*", recurse);
	for (var i=0; i<m.length; i++){
		
			switch (m[i].toString()){
					case  mel[0]  :
					case  mel[1]  : 
												 m[i].text = prop[m[i].name] || m[i].text;  
							   					 break;
					case  mel[2]  :
					case  mel[3]  : 
												 m[i].selected = prop[m[i].name];  
							   					 break;
			}
		
	}
}






function anime0(ob, step, start, stop, speed, display_show_property=null, fun_end=null){
var i=start;
var inc, iid;
var deb ="";

speed = speed || 10;

start>stop ? inc=0 : inc=1;

function hide() {
	//if (ob.className == "divpanprog") alert(deb);
	//if (display_show_property){
//		ob.style.display="none";
//	} else {
//		ob.style.visibility="hidden";
//	}
	ob.visible= false;
}

   function hhi(){
	inc ? i+=step : i-=step;
		//alert(i+"__"+step);
		
	if (i-step<0) hide();

	if ((i>stop && !inc) || (i<stop && inc)) {
		//curopop=i;
		//deb+=i+"__"+step+"\n";
		//a(i);
		ob.alpha = i;
		//window.setTimeout(hhi,speed);
	} else {
		//alert("ssssssss");
		//if (ob.className == "divpanprog") alert(deb);
		if (fun_end) fun_end.call();
		clearInterval (iid);
	}
   }

     //hhi();
    iid = setInterval(hhi, speed);

	if (start==0) {
	//if (display_show_property)
		//ob.style.display=display_show_property;
			//else
			ob.alpha = 0;  
			ob.visible = true;
}
	

    
   return iid; 
}


//position


function getxy(ob) {   
	var x = 0, y = 0;
	while (ob) {
		x+=  ob.x;
		y+=  ob.y;
		ob = ob.parent;
	}
	return {x:x,
			y:y};
}


function alxy(ob,x=0,y=0, cx=0,cy=0){
	if (!(x is Number)) { y=x.y;  x=x.x;}
	ob.x = x+cx; ob.y =y+cy;
}


function alxyg(ob,x=0,y=0, cx=0,cy=0){
	//if (!(x is Number)) { y=x.y; x=x.x;}
	if (!(x is Number)) { y=x.localToGlobal(new Point(0, 0)).y;  x=x.localToGlobal(new Point(0, 0)).x;	}
	//if (!(x is Number)) { y=getxy(x).y; x=getxy(x).x;}
	//if (!(x is Number)) { y=x.localToGlobal(new Point(0, 0)).y; x=x.localToGlobal(new Point(0, 0)).x;}
	//ob.x=ob.globalToLocal(new Point(0, 0)).x;  ob.y=ob.globalToLocal(new Point(0, 0)).y; 
	ob.x = x+cx; ob.y =y+cy;
}

function alxyl(ob,x=0,y=0, cx=0,cy=0){
	if (!(x is Number)) { y=x.globalToLocal(new Point(0, 0)).y;  x=x.globalToLocal(new Point(0, 0)).x;}
	ob.x = x+cx; ob.y =y+cy;
}




function al_siz(ob,w=0,h=0, cw=0,ch=0){
	if (!(w is Number)) { h=w.height; w=w.width;}
	//if (!(x is Number)) { y=x.localToGlobal(new Point(0, 0)).y; x=x.localToGlobal(new Point(0, 0)).x;}
	//ob.x=ob.globalToLocal(new Point(0, 0)).x;  ob.y=ob.globalToLocal(new Point(0, 0)).y; 
	ob.width = w+cw; ob.height = h+ch;
}


function al_sc(ob,x,y=0){
	if (!(x is Number)) { y=x.scaleY; x=x.scaleX;}
		else if (!y) y = x;
	ob.scaleX = x;
	ob.scaleY = y;
}


//test
function al_r(ob, cx=0, cy=0){
		var cot = stage.stageWidth;
	///ob.x = ob.parent.globalToLocal(new Point(stage.stageWidth - ob.width,0)).x + cx;
	//var rwork = stage.stageWidth;
	//ob.x = (ob.parent.localToGlobal(new Point(0, 0)).x) + stage.stageWidth - ob.width +  cx;
	  ob.x =  cot - ob.width +  cx;	 	
}


function al_ca(l,cx=0, cy=0){
		var r = function(){
		  l.x =  (stage.stageWidth - l.width) / 2 + cx;
	  	  l.y =  (stage.stageHeight - l.height) / 2 + cy;
	};
stage.addEventListener("resize", r);
return r;
}


function al_b(ob, cx=0, cy=0){
	var cot = stage.stageHeight;
	if (!(cx is Number))  cot = cx.height;
	//ob.y =   inplace.globalToLocal(new Point(0, 0)).y + (stage.stageHeight - ob.height);
	//ob.y = ob.parent.localToGlobal(new Point(0, stage.stageHeight - ob.height)).y + cy;  //(stage.stageHeight - ob.height);
	ob.y =  cot - ob.height +  cy;
}



function al_c(ob, inobxy=null,  cx=0, cy=0){
	if (!inobxy) inobxy = stage;
				else inobxy = {stageWidth : inobxy.width, stageHeight : inobxy.height};  
				
		ob.x = (inobxy.stageWidth - ob.width) / 2  + cx;
    	ob.y = (inobxy.stageHeight  - ob.height) /2  + cy;
}




//test
function al_r2(ob,  cx=0, cy=0){
	ob.x = getxy(ob.parent).x;// - ob.width + cx;
	ob.y+= cy;
}



//events
/*
 * 
 * постоянно для элемента
 * ----------------------------
 * setblur(infsen, changePropSensor, 2000, "onlyChange");
 * 
 */

function setblur(mob, fun, tim=5000, onlyChange=false, closeClickSelf=false){
	
	if (!isA(mob)) mob = [mob];
	var fStageClick;
	var fChange;
	var id;
	
	var __ismainele = function(e) {
		for (var i=0; i<mob.length; i++) if (mob[i].contains(e.target)) return true;
		return false;
	};
	
	var __whiteforaction = function(e) {
		if (id) clearTimeout(id);
		id = setTimeout(function(){ /*a("fc=="+fChange);*/ if (fChange) fun(); if (onlyChange) fChange = false;  if (fStageClick) stage.removeEventListener(MouseEvent.CLICK ,stagee); fStageClick=false;  }, tim);
		if (!fStageClick) 
			stage.addEventListener(MouseEvent.CLICK ,stagee);
		fStageClick = true;
	}
	
	
	mob[0].addEventListener(MouseEvent.ROLL_OUT, __whiteforaction);
	
	mob[0].addEventListener(MouseEvent.ROLL_OVER ,function(){	
		clearTimeout(id);	
	});
	
	
	if (onlyChange)
		mob[0].addEventListener("change" ,function(){if (fChange) return;   fChange = true;  __whiteforaction()});
	else fChange = true;
	
	var stagee = function(e){
		//a("st click");
		//if (__ismainele(e) && !closeClickSelf) return;
		if (__ismainele(e)) return;
		//a("dddddddddddddd");
		fStageClick = false;
		clearTimeout(id);
		stage.removeEventListener(MouseEvent.CLICK ,stagee);
		if (fChange) fun.call();
		if (onlyChange) fChange = false;
	};
	
	
	var forse = function(){
		
	};
	
	

}




/**
 * ------------------------------ 
 * shine([o.sb,o.me],0.01,0.1, 0.4);
 * 
 */
function shine(ob, stepD=0.02, stepS=0.1, dimlyQ=0.4) {

	var di;
	
		var shiniest = function (){
			if (di === true){
				 anime0(ob,stepD,dimlyQ,1,1, null, function(){ di = false; trace(di); });
				 di = 0;
			}
		};
		var dimly = function (){
			if (di === false){
				 anime0(ob,stepD,1,dimlyQ,1, null, function(){  di = true; trace(di); });
				 di = 0;
			}
		};	
		
		ob.addEventListener(MouseEvent.ROLL_OVER,shiniest);
		ob.addEventListener(MouseEvent.ROLL_OUT,dimly);
	
	  function forsedimly() {
		 	anime0(ob,stepD,1,dimlyQ,1, null, function(){ di = true;});
	  }
	forsedimly();		  
}

function addev(el, ev, fun){
		/*
			rollOut
			rollOver
			mouseWheel
			mouseOut
			mouseMove
			doubleClick
		*/
		el.addEventListener(ev, fun, false);
}


function remchi(ob){
	if (ob.numChildren) while (ob.numChildren - 1) ob.removeChildAt(1);	
}

function remchi_2(ob){
	while (ob.numChildren) ob.removeChildAt(0);
}


/*
 * 
 * var t:TextFormat = new TextFormat();
	t.underline = true;

this.addEventListener("rollOver", function(){
	oo.setStyle("textFormat", t);
});

this.addEventListener("rollOut", function(){
	oo.setStyle("textFormat",null);							   
});
 * 
 */
 
function drag(ob, activ=false, exceptChild=null, funMove=null){
	//mm.buttonMode = true;
	ob.addEventListener(MouseEvent.MOUSE_DOWN, down);
	ob.addEventListener(MouseEvent.MOUSE_UP, up);
	if (funMove){
		ob.addEventListener(MouseEvent.MOUSE_MOVE, function(e){
				funMove.call(this, e);	
		});
	}
	
	function __ischildexp(e){
		if (e && exceptChild)
	    	for each (var i in exceptChild)
	    		if (i === e.target) return true; 
	    return false;	
	}
	
	function down(e:MouseEvent):void {
	    //e.target.startDrag();
	    if (!__ischildexp()) 
	    		ob.startDrag();
	}
	
	//stage.addEventListener(MouseEvent.MOUSE_MOVE, dragMe);
	function dragMe(e:MouseEvent):void {
    	e.updateAfterEvent();
	}
	
	function up(e:MouseEvent):void {
	    	ob.stopDrag();
	    	e.updateAfterEvent();
	    //a(e.stageX +"___"+ e.target.x);
	}
	if (activ) down(null);
	
}




/*
//test
function setTree(list, data){
			var xml:XML = new XML("<r></r>");
				var n = 0;			
				for (var i in data){
					var dd = xml.appendChild((new XML("<d label='"+data[i].name+"' data='"+(data[i].data ?  data[i].data : "")+"'></d>")));
						dd.children()[n].appendChild(<d label='dddd'></d>);
					n++;
				}
				
			list.dataProvider = new TreeDataProvider(xml);
}
*/



function prm(ob){
	trace(ob.name, "a="+ob.transform.matrix.a.toFixed(4), "b="+ob.transform.matrix.b.toFixed(4), "c="+ob.transform.matrix.c.toFixed(4), "d="+ob.transform.matrix.d.toFixed(4), "tx="+ob.transform.matrix.tx, "ty="+ob.transform.matrix.ty,  ob.width.toFixed(0)+"x"+ob.height.toFixed(0)); 
}

		
function rotateAroundCenter (ob:*, angleDegrees:Number, x,y, old = null) {
      var m:Matrix= old || ob.transform.matrix;
    	  m.tx -= x;
      	  m.ty -= y;
      	  m.rotate (angleDegrees*(Math.PI/180));
          m.tx += x;
          m.ty += y;
         ob.transform.matrix=m;
       return(m);  
 }
 
 /*
 private function drawRotated(buffer:BitmapData, img:BitmapData, x:Number, y:Number, angle:Number = 0, scaleX:Number = 1, scaleY:Number = 1):void {
	var mat:Matrix = new Matrix();
	mat.translate(-img.width/2.0, -img.height/2.0);
	mat.scale(scaleX, scaleY);
	mat.rotate(angle);
	mat.translate(x, y);
	buffer.draw(img, mat, null, null, null, true);
}
*/


function mouseDownMove(el, fun){
	var down;
	addev(el, "mouseUp", function(){down=false;});
	addev(el, "mouseDown", function(){down=true;});
	addev(el, "mouseMove", function(e){if (down) fun.call(this, e);});
	 
}
 
 
function getMContrast(m=""){
	var matrix:Array = new Array();
	 switch (m){
	 	case 'many' :
	 					matrix = [0.6,0,0,0,
	 							  26,0,0.6,0,
	 							  0,26,0,0,
	 							  0.6,0,26,0,
	 							  0,0,1,0];
	 					break;
	 					
	 	
		default : 
			matrix=matrix.concat([0.5,0.5,0.5,0,0]);// red
			matrix=matrix.concat([0.5,0.5,0.5,0,0]);// green
			matrix=matrix.concat([0.5,0.5,0.5,0,0]);// blue
			matrix=matrix.concat([0,0,0,1,0]);// alpha
	}
	return(matrix);		
}
 
 

/*
 * 
 * добавление без верхней матрицы
 */
function insWEffect(ob, obin=null){
	obin = obin || ob.parent;
	var mr:Matrix = obin.transform.matrix;
	var m:Matrix =  ob.transform.matrix;
	var x = m.tx, y = m.ty;
		
	//m.identity();
	m.a = mr.a;
	m.d = mr.d;
	m.b = -mr.b;
	m.c = -mr.c;
	
	m.tx = obin.globalToLocal(new Point(x,y)).x;
	m.ty = obin.globalToLocal(new Point(x,y)).y;
	
	ob.transform.matrix = m;
}


/*
 * 
 * ---------------
 *      rc.contextMenu = getMenu([
 *      	{label : "nik", fun : function(){ a("ss"); }}, function(){ l1.selectedItem  = e.mouseTarget.data; itemMove();  l1.contextMenu.customItems[0].enabled = parseInt(curNode.part);  } } }
 *      ]);
 *      ///
 * 
 */
function getMenu(mi, funOpenMenu=null) {
	/*
	 import flash.ui.ContextMenu;
	 import flash.events.ContextMenuEvent;
	 import flash.ui.ContextMenuItem;
	*/
	
	/*
	  	    //Для глоб закрепления приложения flex
            import mx.core.FlexGlobals;
 
            private function init():void {
                var customMenuItem1:ContextMenuItem = new ContextMenuItem("Flex SDK " + mx_internal::VERSION, false, false);
                var customMenuItem2:ContextMenuItem = new ContextMenuItem("Player " + Capabilities.version, false, false);
                var contextMenuCustomItems:Array = FlexGlobals.topLevelApplication.contextMenu.customItems;
                contextMenuCustomItems.push(customMenuItem1);
                contextMenuCustomItems.push(customMenuItem2);
            }
 
	 */
	
	
	var cm:ContextMenu = new ContextMenu();
	//cm.clipboardMenu = true;
	cm.hideBuiltInItems();			   
	if (funOpenMenu)
		cm.addEventListener(ContextMenuEvent.MENU_SELECT, funOpenMenu);      //при создании
	for each(var p in mi){
		var cmi = new ContextMenuItem(p.label, false);
		cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, p.fun); 
		cm.customItems.push(cmi); 
	}		

   return cm;
}


function cptoUTF(s){
	if (s){
		var ba:ByteArray = new ByteArray();			
		ba.writeMultiByte(s, "windows-1251");
		ba.position = 0;
		return ba.readMultiByte(ba.length, "utf-8");
	} 
 return null;	
}



/*
	inf11.buttonMode = true;
	inf11.mouseChildren = false; 
 * 
 */








function en(el, ch=true, alpha=0.2){
	   		if (ch) {
	   			if ("enabled" in el) el.enabled = true;
	   			//if (!(el is Label)) el.alpha = 1;
	   			 //el.enabled = true;
	   			 // if (!(el is InteractiveObject) || (el is Label)) el.alpha = 1;
	  			 if (!('setFocus' in el) || (el is Label)) el.alpha = 1;
	   		} else {
	   			if ("enabled" in el) el.enabled = false;
	   			//if (!(el is Label)) el.alpha = alpha;
	   			     //el.enabled = false;
   			// if (!(el is InteractiveObject) || (el is Label)) el.alpha = alpha;
			 if (!('setFocus' in el) || (el is Label)) el.alpha = alpha;
	   		}
 }
	
	   

function enall(obin, ch=true, alpha=0.2){
		getchi(obin, "*", true, null, function(el){ 
			if ("enabled" in el){ 
						el.enabled = ch;
						el.alpha = ch ? 1 : alpha;  
				}
	});	
}


function addEvEnter(el, fun, ev="keyDown"){
	
	el.addEventListener(ev, function(e){
			if (e.keyCode == 13) fun.call();		
	});
	
}

/*trace(getFirstUniq(m, "id"));
 *
 */
function getFirstUniq(ob, prop=null, starti=0){
	var lastID = starti;
	for (var p in ob) {
		var inid = false;
		for (var p2 in ob)
			if ((prop && ob[p2][prop] == lastID) || (!prop && ob[p2] == lastID)) inid = true;   
		if (!inid)  break; 
		lastID++;
    }
	return lastID; 	
}


/*
 * trancparament ob in arr
 * 
 */
function gettranc(ob){
	var res = [];
		for (var i in ob) res.push(i);
	return res;	
}




function isina(ob, sub, prop=null){
	for (var p in ob) if ((prop && ob[p][prop] == sub) || (!prop && ob[p] == sub)) return true;
	return false; 	
}

/*
 *   if (!setcombo(place.rf.testper, ob.test_period)){
									  		place.rf.testper.addItem({label : ob.test_period});
									  		place.rf.testper.selectedIndex = place.rf.testper.length-1; 
									  		
									  }
 * 
 */
function setcombo(ob, v, type=0, prop='label', def=0) {
		for(var i=0; i<ob.length; i++) {
			var yes = false;
			if (!type  	 ) if (ob.getItemAt(i)[prop] == v) yes = true;    
			if (yes) {
				ob.selectedIndex = i;
				return i + 1;
		}
	}
	ob.selectedIndex = def
	return (false);	
}



 function setcombo_flex(ob, v, type=0, prop='label', def=0) {
          	
			for(var i=0; i<ob.dataProvider.length; i++) {
			var yes = false;
			if (!type  	 ) if (ob.dataProvider[i][prop] == v) yes = true;    
			if (yes) {
				ob.selectedIndex = i;
				return i + 1;
					}
				}
				ob.selectedIndex = def
				return (false);	
	}
	
	

function setMaxii(el, min=0, max=9999, prop='text'){
	addev(el, "change", function(e){
		if (parseFloat(el[prop])>parseFloat(max) &&  !el[prop].match(/\.$/)) el.text = max; 
		if (parseFloat(el[prop])<parseFloat(min) &&  !el[prop].match(/\.$/)) el.text = min;
	});
	addev(el, "focusOut", function(e){
		if (el[prop]=="") el.text = min; 
	});
}

function inArr(m, v, prop=""){
	for each (var p in m) if (!prop && p == v || prop && prop in p && p[prop] == v) return true; 
	return false;
}



function setInputDef(el, value, colorDef=0xd3d3d3, prop="text") {
	
	    var defs = el.getStyle("textFormat");
		var news:TextFormat = new TextFormat();
		news.color = colorDef;
		news.italic = true;
	    
		addev(el,"focusIn",function(){
			if (el[prop] == value) { 
				el[prop] = "";
				el.setStyle("textFormat", defs);
			}
		});
		
		function fout(){
			if (el[prop] == "") {
				el[prop] = value;
				el.setStyle("textFormat", news);
			}
		}
		
		addev(el,"focusOut", fout);
		fout();
}




function getsort(ob, prop=null, addkeyparam=null, parse=true){
	var ob2 = {};
	if (addkeyparam) cpyob(ob2, ob); else ob2 = ob;
	function s(a,b){
			//trace('_________',a, a.toString().match(/\d+/), (!prop && parse && a.toString().match(/\d+/)  > b.toString().match(/\d+/))  );
			if (typeof a == 'object' && !prop){
				a = a._nik_;
				b = b._nik_;
			}
			return ((prop && parse && a[prop.toString().match(/\d+/)] > b[prop.toString().match(/\d+/)]) ||  
					(prop && a[prop] > b[prop]) || (!prop && a > b) ||
					(!prop && parse && a.toString().match(/\d+/) > b.toString().match(/\d+/))) ? 1 : -1;
	}
			
	var m = [];	
	for (var i in ob2) { 
		if (addkeyparam) ob2[i][addkeyparam] = i;
		if (typeof ob2[i] == 'object' && !prop) ob2[i]._nik_ = i;  
			m.push(ob2[i]); 
	}
	m.sort(s);
	
	if (!prop) for (var i in m)  
					if (m[i]._nik_) delete m[i]._nik_;
	
	//dump(m);
	return m;
}






function makeob(m, prop=null){
	var ob  = {};
	//for each(var p in m) if (prop) ob[p.prop] = p;  ob[i] = m[i];
	return ob;
}


// --> 10.10.01 23:10
function getDateSE(t, sec = false){
	var d = new Date(t);
	return  (d.getDate()<10 ? '0'+d.getDate():d.getDate() )+'.'
	+(d.getMonth()<9 ? '0'+(d.getMonth() + 1): (d.getMonth() + 1) )+'.'
	+d.getFullYear()+' '
	+(d.getHours()<10 ? '0'+d.getHours():d.getHours() )+':'
	+(d.getMinutes()<10 ? '0'+d.getMinutes():d.getMinutes() ) 
	+ (sec ? ':' + (d.getSeconds()<10 ? '0'+d.getSeconds():d.getSeconds()) : ''); 
}


function getMaxDay(t){
	var d:Date =  new Date(t);
	var i = 20;
	while (d.getDate()!=1){
		d.setDate(i);
		i++;
	}
	return i-2;
}


function getsdate(s, pt){
	var m = s.split(pt);
	var d = new Date();
	d.setFullYear(m[0]);
	d.setMonth(m[1]-1);
	if (m[2]) d.setDate(m[2]);
	return d;
}


function oneflash(el, startBlur=2, step=0.01, cFlush=0xFF0000){
	//if (!el.filters) el.filters = [];
			//el.filters.push([new GlowFilter (cFlush)]);

			
	var m = el.filters;			
	var op = startBlur;
	var fg = new GlowFilter (cFlush, 0.1);
	var fb = new BlurFilter();
	function setop_(){  
	    op -= step;
		el.filters = [fb, fg];
		 fg.alpha = op < 1  ? op : 1;
		 fb.blurX = op;
		 fb.blurY = op;
		if (op > 0) setTimeout(setop_, 1);
	}
	setop_();
		
}


/*
 	var groupm = [];
	mhint(bb, 'dddddddddddddddd',{}, groupm );
	mhint(bb3, 'cccccccccccccccccccccc',{},  groupm); 
	mhint(ll, 'dsddddddddddd', {font : (new fff()).font, fSize : 14});
 */
 

function mhint(el, str, opt=null, groupm = null){
	if (!opt) opt = {};
	cpyob(opt,{
		  showAlways : false, 
		  durOn      : 8000, 	//активна над объектом
		  cx         : 0,
		  cy         : 0,
		  dur		 : 10,   	//активна после ухода
		  font       : 'Arial',
		  fSize      : 11,        
		  tf 		 : undefined,
		  bColor1 	 : 0xFEFE90,
		  bColor2	 : 0xFEFE90-4000,
		  ss		 : 0.2,
		  sd		 : 0.02,
		  radW       : 4,
		  radH		 : 4,
		  cLine		 : 0,	
		  //grad
		  alphas     : [1, 1],
		  ratios	 : [0x00, 0xFF]
		  //
	 }, true);
	
	
	var t:TextField = new TextField();
	t.text = str;
	t.antiAliasType = 'advanced';
	t.autoSize = 'center';
	if (!opt.tf) opt.tf =  new TextFormat(opt.font , opt.fSize);
	t.setTextFormat(opt.tf);
	
  	var sp:Sprite = new Sprite();
	sp.cacheAsBitmap = true;
  	var fillType:String = GradientType.LINEAR;
  	var colors:Array = [opt.bColor1, opt.bColor2];
  	var alphas:Array = opt.alphas;
  	var ratios:Array = opt.ratios;
  	var matr:Matrix = new Matrix();
  	matr.createGradientBox(t.width, t.height, 0, 0, 0);
  	var spreadMethod:String = SpreadMethod.PAD;
  	sp.graphics.beginGradientFill(fillType, colors, alphas, ratios, matr, spreadMethod);  
	sp.graphics.lineStyle(1, opt.cLine, 1, true);
	sp.graphics.drawRoundRect(t.x,t.y, t.width, t.height, opt.radW, opt.radH);
    sp.addChild(t);	
	
	var di = false;
	
	el.addEventListener("mouseOver", function(){
        forseAllDimly();											   
		if (di === false){
			alxyg(sp, el, 0, (el.width /2) + opt.cx, (el.height > 50 ? el.height / 2 : el.height + 5) + opt.cy);
			//var correctX = sp.localToGlobal(new Point(0, 0)).x - stage.width;
			var correctX = sp.x + sp.width - stage.stageWidth + 30;
			sp.x -=  correctX > 0 ? correctX : 0 ;
			anime0(sp, opt.ss, 0,2, 1, null, function(){ di = true; });
			sp.visible = true;
			stage.addChild(sp);
			di = 0;
			if (!opt.showAlways) setTimeout(function(){if (di === true) { anime0(sp, opt.sd, 1,0, 1, null, function(){ if (stage.getChildByName(sp.name))  stage.removeChild(sp); di = false; }); }  }, opt.durOn);
		}
		   
	});
	
		el.addEventListener("mouseOut", function(){
			if (di === true) {
					setTimeout(function(){anime0(sp, opt.sd, 1,0, 1, null, function(){if (stage.getChildByName(sp.name)) stage.removeChild(sp); di = false; }); }, opt.dur);
					di = 0;
				}
		});
	
	function forseAllDimly() {
		 	for (var i in groupm) groupm[i].visible = false;
	  }

//	setblur([el], function(){ anime0(sp, 0.01, 1,0, 1, null, function(){stage.removeChild(sp); }); }, 300);
if (groupm) groupm.push(sp);
return sp;
}


function isCorrLua(s){
	var a = 0, b = 0;
	for (var i = 0; i < s.length; i++){
		 if (s.charAt(i) == '{') a++;
		 if (s.charAt(i) == '}') b++;
	}
	return a == b;
}



